<%@include
    file="/WEB-INF/jsp/taglibs/taglibs.jsp"
%>
<stripes:layout-render name="/WEB-INF/jsp/layouts/menu.jsp" title="Posts">

<stripes:layout-component name="js">
    <script src="${contextPath}/js/checkboxes-checked.js"></script>
</stripes:layout-component>

<stripes:layout-component name="body">
    <stripes:messages />

    <stripes:form beanclass="com.objecteffects.ilmp.web.action.DraftsActionBean" acceptcharset="utf-8">
        <p>
            ${actionBean.offset + actionBean.context.batchSize} posts searched so far.
            <br />
            <c:choose>
                <c:when test="${fn:length(actionBean.posts) <= 0}">
                    No unliked posts found in this group.  Press Next to search the next group.
                </c:when>
                <c:otherwise>
                    <p>
                    ${fn:length(actionBean.posts)} unliked posts found.
                    Click on the post to see its page on tumblr.
                    </p>
                    <p>
                    Uncheck the ones you want to keep unliked.
                    </p>
                    <p>
                    Press Next to save your changes and search the next group.
                    </p>
                </c:otherwise>
            </c:choose>
        </p>

        <p>
            <stripes:submit
                name="next"
                value="Next"
            />
            <stripes:submit
                name="cancel"
                value="Cancel"
            />
        </p>

        <c:if test="${fn:length(actionBean.posts) > 0}">
            <table class="posts">
                <thead>
                    <tr>
                        <th>
                        </th>
                        <th>
                            Like
                        </th>
                        <th>
                            Click-through url
                        </th>
                        <th>
                            Caption
                        </th>
                    </tr>
                </thead>
                <c:forEach var="post" items="${actionBean.posts}" varStatus="counter">
                    <tbody>
                        <tr>
                            <td>
                                <c:forEach var="photo" items="${post.photos}">
                                    <c:set
                                        var="height"
                                        value="999999"
                                    />
                                    <c:forEach var="size" items="${photo.altSizes}">
                                        <%-- find and save smallest size --%>
                                        <c:if test="${size.height < height}">
                                            <c:set
                                                var="height"
                                                value="${size.height}"
                                            />
                                            <c:set
                                                var="smallPhoto"
                                                value="${size.url}"
                                            />
                                        </c:if>
                                    </c:forEach>
                                </c:forEach>
                                <a href="${post.postUrl}" target="_blank">
                                    <c:choose>
                                        <c:when test="${not empty smallPhoto}">
                                            <img
                                                src="<c:out value='${smallPhoto}' />"
                                            />
                                        </c:when>
                                        <c:otherwise>
                                            (No photo)
                                        </c:otherwise>
                                    </c:choose>
                                </a>
                            </td>
                            <td>
                                <stripes:checkbox
                                    name="selectedPosts"
                                    value="${post.id}"
                                    class="checked"
                                />
                            </td>
                            <td>
                                <c:if test="${not empty post.linkUrl}">
                                    link: ${post.linkUrl}
                                </c:if>
                            </td>
                            <td>
                                <c:if test="${not empty post.caption}">
                                    ${post.caption}
                                </c:if>
                            </td>
                        </tr>
                    </tbody>
                </c:forEach>
            </table>

            <p>
                <stripes:submit
                    name="next"
                    value="Next"
                />
                <stripes:submit
                    name="cancel"
                    value="Cancel"
                />
            </p>
        </c:if>
    </stripes:form>
</stripes:layout-component>
</stripes:layout-render>
